package com.joven.security.controller;

import com.alibaba.fastjson.JSON;
import com.joven.security.model.SysMenu;
import com.joven.security.service.MenuService;
import com.joven.security.utils.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreFilter;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author wzj
 * @Date 2023-03-01 15:47
 **/
@Slf4j
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    public ResultData list() {
        List<SysMenu> sysMenus = menuService.queryAllMenus();
        log.info("controller sysMenus:{}", JSON.toJSONString(sysMenus));
        return ResultData.success(sysMenus);
    }


    @PostMapping("/preFilter")
    @PreFilter(filterTarget = "ids", value = "filterObject%2==1")
    public ResultData preFilterTest(@RequestBody List<Integer> ids) {
        log.info("ids:{}", ids);
        return ResultData.success(ids);
    }
}
